﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RayTrace
{
    public class Metal:Material
    {
        private Vector3D albedo; //漫反射率
        private double fuzz; //模糊参数
        public Metal(Vector3D albedo, double fuzz)
        {
            this.Albedo = albedo;
            this.fuzz = fuzz;
        }
        public double Fuzz { get => fuzz; set => fuzz = value; }
        internal Vector3D Albedo { get => albedo; set => albedo = value; }
        public override bool Scatter(Ray rIn, HitRecord rec, ref
       Vector3D attenuation, ref Ray scattered)
        {
            Vector3D reflected = Form1.Reflect(Vector3D.UnitVector(rIn.Direction), rec.Normal);
            scattered = new Ray(new Point3D(rec.P.X, rec.P.Y, rec.P.Z), reflected + fuzz * Form1.RandomInUnitSphere());
            attenuation = albedo;
            return (Vector3D.DotProduct(scattered.Direction, rec.Normal) >
           0);
        }
    }
}
